<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset id="searchFieldset_currentTable" class="table-search-fieldset layui-hide">
            <legend>{:lang("common.condition_search")}</legend>
            <form class="layui-form layui-form-pane form-search">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("common.start_month")}</label>
                    <div class="layui-input-inline">
                        <input name="m_progress_month_ge" class="layui-input cssMonth"
                               placeholder="{:lang('common.choose')}{:lang('common.start_month')}"
                               value="{$param.m_progress_month_ge|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("common.end_month")}</label>
                    <div class="layui-input-inline">
                        <input name="m_progress_month_le" class="layui-input cssMonth"
                               placeholder="{:lang('common.choose')}{:lang('common.end_month')}"
                               value="{$param.m_progress_month_le|default=''}">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("custom.name")}</label>
                    <div class="layui-input-inline">
                        <select name="m_custom_id_eq" lay-search>
                            <option value="">{:lang("common.choose")}{:lang("custom.name")}</option>
                            {foreach :getMyCustomList() as $val}
                            <option value="{$val.id}">{$val.number}{$val.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>

                {if !auth('roleAccounting')}
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">{:lang("accounting.name")}</label>
                    <div class="layui-input-inline">
                        <select name="m_accounting_id_eq" lay-search>
                            <option value="">{:lang("common.choose")}{:lang("accounting.name")}</option>
                            {foreach :getAccountingList() as $val}
                            <option value="{$val.id}">{$val.name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                {/if}

                <div class="layui-form-item layui-inline" style="margin-left:50px">
                    <button type="submit" class="layui-btn layui-btn-normal" data-type="tableSearch"
                            lay-submit lay-filter="search_currentTable">{:lang("common.btn_search")}
                    </button>
                </div>
            </form>
        </fieldset>

        <table id="currentTable"
               data-auth-generate="{:auth(request()->controller().'/generate')}"
               data-auth-add="{:auth(request()->controller().'/add')}"
               data-auth-edit="{:auth(request()->controller().'/edit')}"
               data-auth-delete="{:auth(request()->controller().'/delete')}"
               data-auth-print="{:auth(request()->controller().'/print')}"
               data-auth-export="{:auth(request()->controller().'/export')}">
        </table>
    </div>
</div>
<script>
    layui.use(['myApp'], function () {
        var myCommon = layui.myCommon;
        window.editMonth = function (id) {
            popupWindow('{:lang("month.see_title")}', 'tally.progress_month/edit?id=' + id, function () {
                myCommon.api.refreshTable();
            }, 800);
        }
        window.generate = function () {
            confirmAndPost('tally.progress_month/generate', '', '{:lang("month.generate_prompt")}', function (res) {
                myCommon.msg.success(res.msg, function () {
                    myCommon.api.refreshTable();
                });
            });
        };

        var columns = [
            {type: "checkbox"}
            , {field: 'id', width: 60, title: '{:lang("common.id")}', sort: true}
            , {field: '_month', width: 70, title: '{:lang("common.month")}', sort: true}
            , {
                field: 'custom_name', minWidth: 120, title: '{:lang("custom.name")}', sort: true
                , templet: myCommon.table.fn, fn: function (value, data) {
                    return '<a onclick="return editMonth(' + myCommon.value(data, 'id') + ')">' + value + '</a>';
                }
            }
            , {field: 'estimate_time', width: 90, title: '{:lang("common.estimate_time_alias")}', sort: true}
            , {field: 'actual_time', width: 90, title: '{:lang("common.actual_time_alias")}', sort: true}
            , {
                field: 'receipt', width: 72, title: '{:lang("month.receipt")}', sort: true,
                templet: myCommon.table.type, typeList: 'receipt_list'
            }
            , {
                field: 'make_account', width: 60, title: '{:lang("month.make_account")}', sort: true,
                templet: myCommon.table.type, typeList: 'make_account_list'
            }
            , {
                field: 'report_forms', width: 80, title: '{:lang("month.report_forms")}', sort: true,
                templet: myCommon.table.type, typeList: 'report_forms_list'
            }
            , {
                field: 'taxes', width: 80, title: '{:lang("month.taxes")}', sort: true,
                templet: myCommon.table.type, typeList: 'taxes_list'
            }
            , {
                field: 'voucher_binding', width: 60, title: '{:lang("month.voucher_binding")}', sort: true,
                templet: myCommon.table.type, typeList: 'voucher_binding_list'
            }
            , {
                field: 'deduction_binding', width: 60, title: '{:lang("month.deduction_binding")}', sort: true,
                templet: myCommon.table.type, typeList: 'deduction_binding_list'
            }
            , {
                field: 'other', width: 60, title: '{:lang("month.other_alias")}', sort: true,
                templet: myCommon.table.type, typeList: 'other_list'
            }
            , {
                field: 'appraise', width: 60, title: '{:lang("common.appraise")}', sort: true,
                templet: myCommon.table.type, typeList: 'appraise_list'
            }
            , {field: 'remark', minWidth: 100, title: '{:lang("month.remark")}'}
            , {field: 'accounting_name', width: 105, title: '{:lang("accounting.name")}', sort: true}
            , {field: 'update_time', width: 148, title: '{:lang("common.update_time")}', sort: true}
        ];
        if (myCommon.checkAuth('delete', '#currentTable')) {
            columns.push({
                width: 50, title: '{:lang("common.operate")}', templet: myCommon.table.tool, operat: ['delete']
            });
        }
        myCommon.table.render({
            where: myCommon.generateCondition()
            , totalRow: true
            , limit: "{$param.limit|default='15'}"
            , cols: [columns]
            , toolbar: ['refresh', {
                auth: 'generate'
                , text: '{:lang("month.btn_generate")}'
                , class: 'layui-btn layui-btn-normal layui-btn-sm'
                , icon: 'fa fa-gears'
                , fn: function () {
                    return 'onclick="generate()"';
                }
            }, 'export']
            , done: function (res) {
                myCommon.tableTotal(this, res.data, ['estimate_time', 'actual_time']);
            }
        });
        myCommon.listen();
    });
</script>
